﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace zytech.common.baseform.edit
{
    public partial class EditGrid : zytech.common.baseform.edit.Edit
    {
        protected int saved = 0;
        public EditGrid()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 点击“增加”按钮时执行本事件
        /// </summary>
        protected override void ue_Add()
        {
            base.ue_Add();
            int irow;
            irow = dataGridView1.Rows.Add();
            saved = 0;
            SavetoolStripButton.Enabled = true;
            CanceltoolStripButton.Enabled = true;
            EdittoolStripButton.Enabled = false;
            AddtoolStripButton.Enabled = false;
            DeltoolStripButton.Enabled = false;
        }
        protected override void AddtoolStripButton_Click(object sender, EventArgs e)
        {
            base.AddtoolStripButton_Click(sender, e);
            this.ue_Add();
        }
        /// <summary>
        /// 点击“修改”按钮时执行本事件
        /// </summary>
        protected override void ue_Modify()
        {
            base.ue_Modify();
            SavetoolStripButton.Enabled = true;
            CanceltoolStripButton.Enabled = true;
            EdittoolStripButton.Enabled = false;
            AddtoolStripButton.Enabled = false;
            DeltoolStripButton.Enabled = false;
            saved = 0;
        }
        protected override void EdittoolStripButton_Click(object sender, EventArgs e)
        {
            base.EdittoolStripButton_Click(sender, e);
            this.ue_Modify();
        }
        /// <summary>
        /// 点击“删除”按钮时执行本事件
        /// </summary>
        protected override void ue_Delete()
        {
            base.ue_Delete();
            int indx;
            indx = dataGridView1.CurrentRow.Index;
            SavetoolStripButton.Enabled = true;
            CanceltoolStripButton.Enabled = true;
            
            DialogResult dir = MessageBox.Show("确定要删除第" + indx.ToString() + "行的数据吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (dir == DialogResult.Yes)        //选是删除当前选中行
            {
                try
                {
                    dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
                }
                catch (DataException ex)
                {
                    MessageBox.Show(ex.Message + "删除数据失败！", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                }
            }
            else                    //选否则不进行删除
            {
            }
        }
        protected override void DeltoolStripButton_Click(object sender, EventArgs e)
        {
            base.DeltoolStripButton_Click(sender, e);
            this.ue_Delete();
        }
        protected override void ue_Save()
        {
            base.ue_Save();
        }
    }
}
